/************************************************************************/
/*  									*/
/*  perturb_SIS.c							*/
/*									*/
/*  Tom Lookabaugh							*/
/*  August 14, 1987							*/
/*  Last Revision: August 15, 1987					*/
/*									*/
/*  DESCRIPTION								*/
/*	Scalar Itakura-Saito version.  If magnitude is less than	*/
/*	0.9*add_off, perturb by a fixed amount; otherwise, perturb	*/
/* 	by a multiple of the original value.  Also store the logarithm	*/
/*	of the result.							*/
/*  RETURNS								*/
/*	No significant value.  Modifies storage pointed to by target.	*/
/*  CALLS								*/
/*	none.								*/
/*									*/
/************************************************************************/

#include "stdvq.h"
#include <math.h>

perturb (source, target, add_off, mult_off)

    double *source;	/* source vector (to be perturbed)		*/
    double *target;	/* target vector 				*/
    double add_off;	/* additive offset				*/
    double mult_off;	/* multiplicative offset			*/

{
    double mag;		/* magnitude of perturbation			*/

    if (source[0] == 0.0)
      mag = add_off;
    else
      mag = (fabs(source[0]) < 0.9*add_off) ? 
		add_off*fabs(source[0])/source[0]:
		(double) mult_off*source[0];
    target[0] = source[0] + mag*((double) rand())/2147483647.0;
    target[1] = log(target[0]);

}
